const lForm = document.querySelector('.login-form')
document.querySelector('#btn-login').addEventListener('click' , async e =>{
    const data = serialize(lForm , {hash:true, empty:true})
    //console.log(data);
    if(!data.username || !data.password){
        return alertShow('请输入用户名或密码')
    }
    if(data.username.length < 8 || data.username.length > 30){
        return alertShow('用户名格式错误')
    }
    if(data.password.length < 6 || data.password.length > 30){
        return alertShow('mima格式错误')
    }
    try {const res = await axios.post('./login', data)
    //console.log(res);res是async await的结果
    const obj = {}
    obj.username = data.username
    obj.token = res.data.data.token
    localStorage.setItem('userMseeage',JSON.stringify(obj))//后台存储用户信息和token
    alertShow(res.data.message)
    setTimeout(e =>{
        location.href = './index.html'
    },800)    
    } catch (err){
        //console.log(err)
    return alertShow(res.response.data.message)
    }
})